package com.ktjy.aop;

import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component("transactionAspect")
@Aspect
public class TransactionAspect {
    Logger logger= LoggerFactory.getLogger(LoggerAspect.class);

    @Before(value = "abc()")
    public void t1(){
        logger.info("手动开启事务");
        logger.info("SqlSession sqlSession = MyBatisUtil.createSqlSession();");
    }

    @AfterReturning(value = "abc()",returning = "result")
    public void t2(Object result){
        logger.info("手动提交事务");
        logger.info("sqlSession.commit();");
    }

    @AfterThrowing(value = "abc()",throwing = "e")
    public void t3(Throwable e){
        logger.info("手动回滚事务");
        logger.info("sqlSession.rollback();");
    }

    @After(value = "abc()")
    public void t4(){
        logger.info("释放资源，关闭连接");
        logger.info(" MyBatisUtil.closeSqlSession(sqlSession);");
    }

    @Pointcut("execution(public boolean insert(com.ktjy.entity.Pet))")
    public void abc(){

    }
}
